/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import DAO.MSSQLConnect;
import java.awt.Container;
import java.awt.Frame;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.swing.JRViewer;

/**
 *
 * @author PEKEM
 */
public class ShowReport extends JFrame{
    
    MSSQLConnect cn = new MSSQLConnect();
    public static void main(String[] args) throws Exception {
        try {
            new ShowReport().Show_ReportDoanhThu("6-2013");
        } catch (JRException | ClassNotFoundException | SQLException e){
            System.out.println("COUSE: " + e.getCause());
            System.out.println("MESSAGE: " + e.getMessage());
            System.out.println("LOCAL MESSAGE: " + e.getLocalizedMessage());
        }
    }
    public Connection getConnection() throws ClassNotFoundException, SQLException, Exception { 
        return cn.getConnect();
    }
    public void Show_ReportDoanhThu(String thang) throws JRException, ClassNotFoundException, SQLException, Exception{
        JasperReport report = JasperCompileManager.compileReport("src\\report\\doanhthu.jrxml");
        HashMap parameters = new HashMap();
        parameters.put("parathang", thang);
        JasperPrint print = JasperFillManager.fillReport(report, parameters, getConnection());
        System.out.println(report.getQuery().toString());
        JRViewer viewer = new JRViewer(print);            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    public void Show_ReportPhieuThue(String makhach) throws JRException, ClassNotFoundException, SQLException, Exception{
        JasperReport report = JasperCompileManager.compileReport("src\\report\\phieuthue.jrxml");
        HashMap parameters = new HashMap();
        parameters.put("makhach", makhach);
        JasperPrint print = JasperFillManager.fillReport(report, parameters, getConnection());
        System.out.println(report.getQuery().toString());
        JRViewer viewer = new JRViewer(print);            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    public void Show_ReportHoaDon(String makhach) throws JRException, ClassNotFoundException, SQLException, Exception{
        JasperReport report = JasperCompileManager.compileReport("src\\report\\hoadon.jrxml");
        HashMap parameters = new HashMap();
        parameters.put("makhach", makhach);
        JasperPrint print = JasperFillManager.fillReport(report, parameters, getConnection());
        System.out.println(report.getQuery().toString());
        JRViewer viewer = new JRViewer(print);            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    public void Show_ReportDatTiec(String mapdt) throws JRException, ClassNotFoundException, SQLException, Exception{
        JasperReport report = JasperCompileManager.compileReport("src\\report\\datiec.jrxml");
        HashMap parameters = new HashMap();
        parameters.put("mapdt", mapdt);
        JasperPrint print = JasperFillManager.fillReport(report, parameters, getConnection());
        System.out.println(report.getQuery().toString());
        JRViewer viewer = new JRViewer(print);            
        viewer.setOpaque(true);
        viewer.setVisible(true);
        this.add(viewer);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setVisible(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
}
